/*
 * OpenFileAction.java
 *
 * Created on March 7, 2005, 11:29 AM
 */

package com.bff.mpd.musicjukebox.lib.actions;

import com.bff.mpd.utils.Utils;
import java.awt.Component;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
/**
 *
 * @author bill
 */
public class OpenTabAction extends AbstractAction {
    
    private final ImageIcon openIcon= new ImageIcon(getClass().getResource("/resources/mpd/open.png"));
    
    private File file;
    private Component parent;
    private JFileChooser fc;
    private JTextArea textArea;
    
    public OpenTabAction(Component parent, JTextArea textArea) {
        super(Utils.getMessage("ACTION_OPEN_NAME"));
        this.textArea = textArea;
        this.parent = parent;
        this.fc = new JFileChooser();
        
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);       
        putValue(Action.SMALL_ICON, openIcon);
    }
    
    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        
        int returnVal = fc.showOpenDialog(parent);
               
        //Query the JFileChooser to get the input from the user
        if(returnVal == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();
            Utils.readFile(textArea, file);
        }
    }   

};
